const config = require('./config')
const express = require('express')
const ParseServer = require('parse-server').ParseServer

const api = new ParseServer(config.ParseServer)

const app = module.exports.app = express()

app.use('/parse', api)

module.exports.onListening = async function () {
  // 初始化实时查询
  const live = config.ParseServer.liveQuery
  if (Array.isArray(live.classNames) && live.classNames.length !== 0) {
    ParseServer.createLiveQueryServer(this)
  }

  // 初始化数据库
  await require('./migrations/initdb')()

  console.log('Listening on ' + config.ParseServer.port)
}
